/* API PROPOSAL for RMI-C PROJECT (V1). */

#ifndef __RMI_H__
#define __RMI_H__

#include <rpc/xdr.h>
#include <stdbool.h>

/* XDR TYPES */

typedef char* wrapstring;

typedef struct xarray_t
{
  int size;
  int * array; /* only for integer type, yet */
} xarray;

extern bool_t xdr_xarray(XDR * xdrs, xarray * xarray);

/* CLIENT API */

struct CLIENT_t; 
typedef struct CLIENT_t CLIENT;

CLIENT * rmi_client_create(char *host,	
			   int port, 
			   unsigned long objecttype, 
			   unsigned long objectkey);

int rmi_client_call(CLIENT *client, 
		    unsigned long methodnum,
		    xdrproc_t inproc, 
		    void *in,
		    xdrproc_t outproc, 
		    void *out);

void rmi_client_destroy(CLIENT *client);

unsigned long rmi_client_lookup(char* object_name, 
				int port, 
				char* host);

/* SERVER API */

struct SERVER_t; 
typedef struct SERVER_t SERVER;
typedef void (*method_t)(void* this, void* in, void* out);

SERVER * rmi_server_create(int port);

int rmi_server_register_method(SERVER * server, 
			       unsigned long objecttype,
			       unsigned long methodnum,
			       xdrproc_t inproc,
			       xdrproc_t outproc,
			       method_t method);

int rmi_server_unregister_method(SERVER * server, 
				 unsigned long objecttype,
				 unsigned long methodnum);

int rmi_server_activate_object(SERVER * server,  
			       unsigned long objecttype,
			       unsigned long objectkey,
			       void * this);

int rmi_server_deactivate_object(SERVER * server,  
				 unsigned long objecttype,
				 unsigned long objectkey);

void rmi_server_run(SERVER * server);

void rmi_serveur_bind(unsigned long object_adress, 
		     char* object_name,
		     int port, 
		     char* host);

#endif /* __RMI_H__ */
